package com.general.framework.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.stp.StpUtil;
import com.general.framework.common.Result;
import com.general.framework.entity.User;
import com.general.framework.service.MenuService;
import com.general.framework.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    private UserService userService;

    @Autowired
    private MenuService menuService;

    @GetMapping("/check-permissions")
    public Result checkPermissions() {
        Long userId = StpUtil.getLoginIdAsLong();
        List<String> permissions = menuService.getPermissionsByUserId(userId);
        return Result.success("当前用户的权限列表：" + permissions);
    }

    @SaCheckPermission("user:list")
    @GetMapping("/users")
    public Result listUsers() {
        List<User> users = userService.findAll();
        return Result.success(users);
    }
}